package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.itcast.crm.domain.Customer;

public interface CustomerDao extends JpaRepository<Customer, Integer> {

	List<Customer> findByFixedAreaIdIsNull();
	
	List<Customer> findByFixedAreaId(String fixedAreaId);

	@Query(value="update Customer set fixedAreaId =?2 where id=?1")
	@Modifying
	void setNoAssociationCustomers(Integer customerIds, String fixedAreaId);
	
	@Query(value="update Customer set fixedAreaId = null where fixedAreaId=?")
	@Modifying
	void clearAllAssociationForFixedArea(String fixedAreaId);
	
	@Query(value="from Customer where telephone = ?")
	Customer findByTelephone(String telephone);

	Customer findByTelephoneAndPassword(String telephone, String password);
	
	@Query(value="select fixedAreaId from Customer where address=?")
	String findFixedAreaIdByAddress(String address);

	


}
